package question3;

import question2.Square;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * 使用上题的矩形类，编程统计若干块土地的相关信息，
 *
 * @FileName Test
 * @Description
 * @Author Sword
 * @date 2024-10-11
 **/
public class Test {
    public static void main(String[] args) {
        //由用户输入每块儿土地的长与宽
        Scanner sc = new Scanner(System.in);
        HashMap<Integer, Square> map = new HashMap<>();

        for (int i = 1; ; i++) {
            System.out.println("请输入长度");
            int length = sc.nextInt();
            if (length == 0){
                break;
            }
            System.out.println("请输入宽度");
            int width = sc.nextInt();
            Square square = new Square(length, width);
            map.put(i, square);

        }


        //程序将相关结果输出
        Set<Map.Entry<Integer, Square>> entries = map.entrySet();
        for (Map.Entry<Integer, Square> entry : entries) {
            Square square = entry.getValue();

            int perimeter = square.getPerimeter(square.getLength(), square.getWidth());
            System.out.println("周长为:" + perimeter);

            int area = square.getArea(square.getLength(), square.getWidth());
            System.out.println("面积为:" + area);
        }
    }
}
